package com.lecture.java8.multithreading;

/**
 * @author luyn
 * @version 1.0
 * @description
 * @date 2021/1/14 17:58
 */
public class WindowTest4 {

    public static void main(String[] args) {
        Window4_1 w1 = new Window4_1();
        new Thread(w1).start();
        new Thread(w1).start();
        new Thread(w1).start();
    }
}

class Window4_1 implements Runnable{
    private  int  ticket = 100;
    @Override
    public void run() {

        while (true) {
            show();
        }
    }

    private synchronized void show() {
        if (ticket > 0) {
                /*try {
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }*/
            System.out.println(Thread.currentThread().getName() + "：卖票，票号：" + ticket);
            ticket--;
        }
    }
}
